package com.xinzhi.service.impl;

import com.xinzhi.mapper.QianshouMapper;
import com.xinzhi.pojo.dto.AddJiaQin;
import com.xinzhi.service.QianshouService;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QianshouServiceImpl implements QianshouService {
    @Autowired
    private QianshouMapper qianshouMapper;

    /**
     * 一级指标新增签收时限和二级指标
     * @return
     */
    @Override
    public Result addQianshou(AddJiaQin addJiaQin) {

        if (addJiaQin.getOne_index()== null || addJiaQin.getTwo_index() == null) {
            return Result.error("新增内容不能为空");
        }

        int result = 0;

        if (addJiaQin.getOne_index().equals("党中央、国务院方针政策")) {
            qianshouMapper.addTwo(addJiaQin.getTwo_index()); // 插入到 two_grade_index 表
            // 注意：这里假设在 Mapper XML 中已经正确定义了获取自增ID的逻辑
            Integer lastInsertedId = qianshouMapper.getLastInsertedId();
            qianshouMapper.insertIntoImplementation(lastInsertedId); // 插入到 Implementation 表
            result = 1; // 假设成功插入了一条数据
        } else if (addJiaQin.getOne_index().equals("省委、省政府决策部署")) {
            // 对省委、省政府决策部署的处理逻辑
            qianshouMapper.addTwos(addJiaQin.getTwo_index());
            Integer lastInsertedId = qianshouMapper.getLastInsertedId();
            qianshouMapper.insertIntoImplementation(lastInsertedId);
            result = 1;
        } else if (addJiaQin.getOne_index().equals("其他主责主页")) {
           // 对其他主责主页的处理逻辑

            qianshouMapper.addTwoss(addJiaQin.getTwo_index());
            Integer lastInsertedId = qianshouMapper.getLastInsertedId();
            qianshouMapper.insertIntoImplementation(lastInsertedId);
            result = 1;        } else {
            return Result.error("没有匹配的数据");
        }

        return result > 0 ? Result.ok("新增成功") : Result.error("新增失败");
    }
}
